<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商品类别</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.all.js"></script>
		<style type="text/css">
			#sfz_pic{position: relative;}/*opacity: 0;*/
			 .upload,.upload1{position: absolute;top: 0;left: 0;width: 100%;height: 100%;opacity: 0;}
			#dp_pic{position: relative;}
			 .upload2{position: absolute;top: 0;left: 0;width: 100%;height: 100%;opacity: 0;}
			#yyzz_pic{position: relative;}
			 .upload3{position: absolute;top: 5%;left: 6%;height: 100%;width: 100%;opacity: 0;}
			#qt_pic{position: relative;}
			 .upload4{position: absolute;top: 5%;left: 6%;height: 100%;width: 100%;opacity: 0;}
			
		</style> 
	</head>

	<body>
		<!--新增弹出框开始-->
		<div class="maskbox">
			<form class="form form-horizontal" id="form-admin-add" method="post">
				<div class="layui-form-item">
	    			<div class="renz_img " id="yyzz_pic" style="margin-left: 120px; margin-top: 20px;">
	    				<input type="hidden" name="logo" id="thumb_1"  value="{$list.logo}"  lay-verify="required" autocomplete="off" class="layui-input"/>
	    				<input type="file" id="upload_1" class="upload1" value="选择图片文件" multiple />
	    				{if condition="$list.logo == null"}
							<span><img class='img_1' id='img_1' id='img_1' style="width: 150px;height: 150px;" src="__LOGO__/1/logomr.png"></span>
						{else /}
							<span><img class='img_1' id='img_1' src="{$list.logo}" style="width: 150px;height: 150px;"></span>
						{/if}
	    			</div>
				</div> 
				<div class="shxx_row clearfix">
					<div class="right">
						<div class="htrig_box">
							<div class="htrig_con">
								<input type="text" value="{$list.id}" id="id" name="id" style="display: none;">
								<input  value="{$list.type_name}" type="text" name="type_name" id="type_name" class="chax_input chax_input2" style="width: 250px; margin-top: 20px;"  lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
				</div>
				<div class="add_btnbox">
					<button type="button" class="add_btn_yes"  lay-submit lay-filter="submit_from">确定</button>
				</div>
			</form>
		</div>
	</body>

</html>
<script>
	layui.use(['form', 'upload'], function() {
		var $ = layui.jquery,
			upload = layui.upload,
			form = layui.form;

		//监听表单提交
		form.on('submit(submit_from)', function(data){
			tijiao();
  			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});


		var uploadInst_1 = upload.render({
			elem: '#upload_1',
			auto: false //选择文件后不自动上传
				,
			choose: function(obj) {
				//将每次选择的文件追加到文件队列
				var files = obj.pushFile();
				//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
				obj.preview(function(index, file, result) {
					$('#img_1').attr('src', result); //图片链接（base64）
					var sendData = result.substring(result.indexOf(";base64,") + 8);
					$.post("{:url('agent/index/upload')}", {
						value: sendData
					}, function(data) {
						if(data.code == '200') {
							$('#thumb_1').val(data.url);
						} else {
							layer.msg(data.msg);
						}
					});
				});
			},
			url: "{:url('agent/index/upload')}",
			accept: 'images'
		});
	});
	//提交表单
	function tijiao() {
		$.ajax({
			type: 'post',
			data: {
				id: $('#id').val(),
				type_name: $('#type_name').val(),
				logo: $('#thumb_1').val()
			},
			url: "{:url('shop/goods_type_update')}",
			success: function(data) {
				if(data.code == 200) {
					layer.msg(data.msg, {
						icon: 1,
						time: 1000
					}, function() {
						window.parent.location.reload();
					});
				} else {
					layer.msg(data.msg, {
						icon: 1,
						time: 1000
					});
				}

			}
		});
	};
</script>